unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, Dialog_View, Uni, UniConnct, UniConfig, UniProvider,
  SQLServerUniProvider, SQLiteUniProvider;

type
  TForm1 = class(TDialogView)
    Btnx_1: TButton;
    Btnx_2: TButton;
    SQLServerUniProvider1: TSQLServerUniProvider;
    SQLiteUniProvider1: TSQLiteUniProvider;
    Btnx_3: TButton;
    Btnx_4: TButton;
    procedure Btnx_1Click(Sender: TObject);
    procedure Btnx_2Click(Sender: TObject);
    procedure Btnx_3Click(Sender: TObject);
    procedure Btnx_4Click(Sender: TObject);
  private
  protected
    procedure SetInitialize;override;
    procedure SetCommParams;override;
    procedure SetGridParams;override;
    procedure SetComboItems;override;
    procedure TryFreeAndNil;override;
  public
    procedure loadTabl(atabl:string);
  public
    procedure OnUniConnctCustomConnectionEventByOBJ(AConnectionMark:string;var OBJA:TUniConfig);
  end;

var
  Form1: TForm1;

implementation

uses
  Class_KzUtils;

{$R *.dfm}

procedure TForm1.Btnx_1Click(Sender: TObject);
var
  I:Integer;
  SQLA:string;
  List:TStringList;
  UniConnct:TUniConnection;
begin
  try
    UniConnct:=UniConnctEx.GetConnection('XTGL');
    try
      UniConnct.StartTransaction;
      //-<
      try
        List:=TStringList.Create;
        List.LoadFromFile(TKzUtils.ExePath+'tabl1.txt');
        for I:=0 to List.Count-1 do
        begin
          sqla:='insert into  tabl1 (card_code) values (%s)';
          SQLA:=Format(SQLA,[QuotedStr(Trim(List.Strings[I]))]);
          UniConnctEx.ExecuteSQL(SQLA,UniConnct);
        end;
      finally
        FreeAndNil(List);
      end;      
      //->
      UniConnct.Commit;
    except
      on E:Exception do
      begin
        UniConnct.Rollback;
        raise Exception.Create(E.Message);
      end;
    end;
  finally
    FreeAndNil(UniConnct);
  end;
end;

procedure TForm1.OnUniConnctCustomConnectionEventByOBJ(
  AConnectionMark: string; var OBJA: TUniConfig);
begin
  OBJA.FUnixType:=UniConfig.CONST_PROVIDER_SQLSRV;
  OBJA.FUnixServ:='.';
  OBJA.FUnixUser:='sa';
  OBJA.FUnixPswd:='sa';
  OBJA.FDataBase:='DBZCGL_DSYY';
end;

procedure TForm1.SetComboItems;
begin
  inherited;

end;

procedure TForm1.SetCommParams;
begin
  inherited;

end;

procedure TForm1.SetGridParams;
begin
  inherited;

end;

procedure TForm1.SetInitialize;
begin
  inherited;
  UniConnctEx.ConnctMode:=cmByOBJ;
  UniConnctEx.OnUniConnctCustomConnectionEventByOBJ:=self.OnUniConnctCustomConnectionEventByOBJ;
end;

procedure TForm1.TryFreeAndNil;
begin
  inherited;

end;

procedure TForm1.Btnx_2Click(Sender: TObject);
var
  I:Integer;
  SQLA:string;
  List:TStringList;
  UniConnct:TUniConnection;
begin
  try
    UniConnct:=UniConnctEx.GetConnection('XTGL');
    try
      UniConnct.StartTransaction;
      //-<
      try
        List:=TStringList.Create;
        List.LoadFromFile(TKzUtils.ExePath+'tabl2.txt');
        for I:=0 to List.Count-1 do
        begin
          sqla:='insert into  tabl2 (card_code) values (%s)';
          SQLA:=Format(SQLA,[QuotedStr(Trim(List.Strings[I]))]);
          UniConnctEx.ExecuteSQL(SQLA,UniConnct);
        end;
      finally
        FreeAndNil(List);
      end;      
      //->
      UniConnct.Commit;
    except
      on E:Exception do
      begin
        UniConnct.Rollback;
        raise Exception.Create(E.Message);
      end;
    end;
  finally
    FreeAndNil(UniConnct);
  end;
end;
procedure TForm1.loadTabl(atabl: string);
var
  I:Integer;
  SQLA:string;
  List:TStringList;
  UniConnct:TUniConnection;
begin
  try
    UniConnct:=UniConnctEx.GetConnection('XTGL');
    try
      UniConnct.StartTransaction;
      //-<
      try
        List:=TStringList.Create;
        List.LoadFromFile(TKzUtils.ExePath+format('%S.txt',[atabl]));
        for I:=0 to List.Count-1 do
        begin
          sqla:='insert into  %S (card_code) values (%s)';
          SQLA:=Format(SQLA,[atabl,QuotedStr(Trim(List.Strings[I]))]);
          UniConnctEx.ExecuteSQL(SQLA,UniConnct);
        end;
      finally
        FreeAndNil(List);
      end;      
      //->
      UniConnct.Commit;
    except
      on E:Exception do
      begin
        UniConnct.Rollback;
        raise Exception.Create(E.Message);
      end;
    end;
  finally
    FreeAndNil(UniConnct);
  end;
end;
procedure TForm1.Btnx_3Click(Sender: TObject);
begin
  loadTabl('tabl3');
end;

procedure TForm1.Btnx_4Click(Sender: TObject);
begin
  loadTabl('tabl4');
end;

end.
 